package com.uyaer.wheel
{
	import com.uyaer.wheel.common.Common;
	import com.uyaer.wheel.res.ResManager;
	
	import nape.geom.Vec2;
	import nape.phys.Body;
	import nape.phys.BodyType;
	import nape.phys.Material;
	import nape.shape.Circle;
	
	import starling.core.Starling;
	import starling.display.MovieClip;
	
	public class Player extends MovieClip
	{
		public var body:Body;
		public var dy:Number = 0; //位移
		private var py:Number=-1; //上一次的位置
		public function Player()
		{
			super(ResManager.me.getTextures("ball_c1"), 6);
			
			this.pivotX = this.width>>1;
			this.pivotY = this.height >>1;
			
			body = new Body(BodyType.DYNAMIC,new Vec2(Common.W/2,Common.H/2));
			body.shapes.add(new Circle(16,null,Material.rubber()));
			body.mass = 1.78;
			body.userData.data = {"texture":this};
			body.cbTypes.add(Common.meCbType);
			body.space = Common.space;
//			body.shapes.at(0).sensorEnabled = true;
			Starling.juggler.add(this);
		}
		
		public function updateDy():void{
			if(py<0){
				py = this.y;
			}else{
				dy = this.y - py;
				py = this.y;
			}
		}
		
		public function destory():void{
			Starling.juggler.remove(this);
			body.space.bodies.remove(body);
			body.userData.data = null;
			body.cbTypes.clear();
			body.shapes.clear();
			body = null;
			super.dispose();
			this.removeFromParent(true);
		}
		
		
	}
}